package com.bazaaroid.server.gae.core.persistence.model.partner;

import java.util.Date;

import javax.jdo.annotations.Embedded;
import javax.jdo.annotations.EmbeddedOnly;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;

import com.bazaaroid.server.gae.core.persistence.model.AbstractModel;
import com.google.appengine.api.datastore.Key;

@SuppressWarnings("serial")
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable ="true")
public class Discount extends AbstractModel  {

	@Persistent
	private String name;
	@Persistent
	private String description;
	@Persistent
	private int percentage;
	@Persistent
	private double priceWithDiscount;

	@PersistenceCapable(detachable = "true")
	@EmbeddedOnly
	public static class TimePeriod {

		@Persistent
		private Date dateFrom;
		@Persistent
		private Date dateTo;

		public TimePeriod() {}

		public Date getDateFrom() {
			return dateFrom;
		}

		public void setDateFrom(Date dateFrom) {
			this.dateFrom = dateFrom;
		}

		public Date getDateTo() {
			return dateTo;
		}

		public void setDateTo(Date dateTo) {
			this.dateTo = dateTo;
		}
	}

	@Persistent(defaultFetchGroup = "true")
	@Embedded
	private TimePeriod timePeriod;

	@Persistent(defaultFetchGroup = "true")
	private Key product;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}
	
	public void setDescription(String description) {
		this.description = description;
	}
	
	public int getPercentage() {
		return percentage;
	}

	public void setPercentage(int percentage) {
		this.percentage = percentage;
	}

	public Double getPriceWithDiscount() {
		return priceWithDiscount;
	}

	public void setPriceWithDiscount(Double priceWithDiscount) {
		this.priceWithDiscount = priceWithDiscount;
	}

	public TimePeriod getTimePeriod() {
		return timePeriod;
	}

	public void setTimePeriod(TimePeriod timePeriod) {
		this.timePeriod = timePeriod;
	}

	public Key getProduct() {
		return product;
	}

	public void setProduct(Key product) {
		this.product = product;
	}
}
